package message;

import java.io.File;
import java.net.Socket;

import serveur.AnnonceurServerDelegate;

import common.CommonFile;
import common.ReceiveFile;
import common.SendFile;

public class MessagePutFile extends Message {

	protected String m_sNomFicher;
	private AnnonceurServerDelegate m_AnnonceurServerDelegate;
	private Socket m_ControlSocket;
	
	
	public void setmControlSocket(Socket mControlSocket) {
		m_ControlSocket = mControlSocket;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MessagePutFile ()
	{
		m_iMessageId = Message.PutFileId;
		m_sMessageName = Message.sPutFileName;
		m_sNomFicher = "";
	}
	
	public String getM_sNomFicher() {
		return m_sNomFicher;
	}

	public void setM_sNomFicher(String mSNomFicher) {
		m_sNomFicher = mSNomFicher;
	}
	
	public void setM_AnnonceurServerDelegate(AnnonceurServerDelegate m_AnnonceurServerDelegate) {
		this.m_AnnonceurServerDelegate = m_AnnonceurServerDelegate;
	}

	public AnnonceurServerDelegate getM_AnnonceurServerDelegate() {
		return m_AnnonceurServerDelegate;
	}
	
	@Override
	public	boolean execute() {
		// TODO Auto-generated method stub
		File fileToRecv = new File( this.m_sCurrentFolder + File.separator + m_sNomFicher );
		System.out.println(fileToRecv.toString());
		ReceiveFile recvFile = new ReceiveFile(fileToRecv, m_AnnonceurServerDelegate.getM_dataSocket(), m_ControlSocket );
		recvFile.setM_sPathFile(this.m_sCurrentFolder + File.separator + m_sNomFicher);
		m_AnnonceurServerDelegate.setM_recvFile( recvFile );
		m_AnnonceurServerDelegate.setM_TransfertMode(CommonFile.ReceiveTransfertMode);
		System.out.println("execute::run");
		m_AnnonceurServerDelegate.run();
		return false;
	}
}
